var oScorm = pipwerks.SCORM; 
function loadOLM()
{
	if( typeof sessionStorage == "undefined" || sessionStorage.disabled )
	{
		alert( "You must enable cookies for this course to work properly." );
	}
	else
	{
		if( !sessionStorage.getItem( "course_started" ) )
        {
        	
            sessionStorage.clear();
            
            sessionStorage.setItem( "course_started", "1" );
            sessionStorage.setItem("topic1", "0");
    		sessionStorage.setItem("topic2", "0");
    		sessionStorage.setItem("topic3", "0");
    		sessionStorage.setItem("topic4", "0");
    	}
	}
	
	initializeSCORM();
}

function visitTopic1()
{
	sessionStorage.setItem("topic1", "visited");
	showQuiz();
}
function visitTopic2()
{
	sessionStorage.setItem("topic2", "visited");
	showQuiz();
}
function visitTopic3()
{
	sessionStorage.setItem("topic3", "visited");
	showQuiz();
}
function visitTopic4()
{
	sessionStorage.setItem("topic4", "visited");
	showQuiz();
}
function showQuiz()
{
	var topic1Visited = sessionStorage.getItem("topic1");
	var topic2Visited = sessionStorage.getItem("topic2");
	var topic3Visited = sessionStorage.getItem("topic3");
	var topic4Visited = sessionStorage.getItem("topic4");
	
	if( topic1Visited == "visited" && topic2Visited == "visited" && topic3Visited == "visited" && topic4Visited == "visited")
	{
		document.getElementById("quiz-link").style.display="inline";
	}
}
function initializeSCORM()
{
	var lmsConnected = oScorm.init();
	
	var getStarted = sessionStorage.getItem( "course_started" );
	
	if( lmsConnected && getStarted == "1" )
	{
        oScorm.set( "cmi.success_status", "unknown" );
		oScorm.set( "cmi.lesson_status", "incomplete" );
		oScorm.set( "cmi.completion_status", "incomplete" );
		
		sessionStorage.setItem( "course_started", "2" );
    }
}function reportScores()
{	
	oScorm.set("cmi.score.raw", 83 );
	oScorm.set("cmi.score.min", 0 );
	oScorm.set("cmi.score.max", 100 );
	oScorm.set("cmi.score.scaled", .83 );
	
	oScorm.set( "cmi.success_status", "passed" );
	oScorm.set( "cmi.completion_status", "completed" );
	oScorm.set( "cmi.lesson_status", "passed" );

	oScorm.save();
}

function finishOLM()
{
	oScorm.save();
	oScorm.quit();
}

